package com.bawei.play

import android.content.Context
import android.util.AttributeSet
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.Orientation

/**
 * 页面切换
 */
class SnapPageLayoutManager constructor(context: Context):LinearLayoutManager(context) {

    //该帮助类主要用于Item切换效果，类似抖音视频切换效果
    private val mSnapHelper = PagerSnapHelper() //LinearSnapHelper()
    constructor(context: Context, orientation: Orientation): this(context)
    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int): this(context)

    constructor(context: Context, orientation: Orientation, reverseLayout: Boolean ): this(context)
    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int ): this(context)

    override fun onAttachedToWindow(view: RecyclerView?) {
        super.onAttachedToWindow(view)
        mSnapHelper.attachToRecyclerView(view)
    }

    //为LayoutManager设置更多的预留空间
    override fun getExtraLayoutSpace(state: RecyclerView.State?): Int {
        return 500
    }


}